package com.nbsaas.boot.user;

import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import com.nbsaas.boot.user.api.domain.request.UserAccessLogRequest;
import com.nbsaas.boot.user.api.domain.request.UserAccessLogSearch;
import com.nbsaas.boot.user.api.domain.response.UserAccessLogResponse;
import com.nbsaas.boot.user.api.domain.simple.UserAccessLogSimple;
import com.nbsaas.boot.user.api.apis.UserAccessLogApi;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import jakarta.annotation.Resource;

/**
*  访问日志控制器
*/
@RequiresAuthentication
@RestController
@RequestMapping("/userAccessLog")
public class UserAccessLogController {


    @Resource
    private UserAccessLogApi userAccessLogApi;

    /**
    * 搜索数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("userAccessLog:search")
    @PostMapping("/search")
    public PageResponse <UserAccessLogSimple> search(@RequestBody UserAccessLogSearch request) {
        return userAccessLogApi.search(request);
    }

    /**
    * 列表数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("userAccessLog:list")
    @PostMapping("/list")
    public ListResponse<UserAccessLogSimple> list(@RequestBody UserAccessLogSearch request) {
        return userAccessLogApi.list(request);
    }

    /**
    * 添加数据
    *
    * @param request
    * @return
    */
    @RequiresPermissions("userAccessLog:create")
    @CreateData
    @PostMapping("/create")
    public ResponseObject <UserAccessLogResponse> create(@RequestBody @Validated(AddOperator.class) UserAccessLogRequest request) {
        return userAccessLogApi.create(request);
    }

   /**
   * 修改数据
   * @param request
   * @return
   */
   @RequiresPermissions("userAccessLog:update")
   @UpdateData
   @PostMapping("/update")
   public ResponseObject<UserAccessLogResponse> update(@RequestBody @Validated(UpdateOperator.class) UserAccessLogRequest request) {
       return userAccessLogApi.update(request);
   }

    /**
    * 删除数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("userAccessLog:delete")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) UserAccessLogRequest request) {
        return userAccessLogApi.delete(request);
    }

    /**
    * 查看数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("userAccessLog:view")
    @PostMapping("/view")
    public ResponseObject <UserAccessLogResponse> view(@RequestBody @Validated(ViewOperator.class) UserAccessLogRequest  request) {
        return userAccessLogApi.view(request);
    }
}